layui.use(['common','layer','table','form',],function(){
	var $ = layui.$,
    	layer = layui.layer,
    	form = layui.form,
    	common = layui.common,
    	table = layui.table;
	
	
	var  tableIns = table.render({
		elem: '#roleList', //指定原始表格元素选择器（推荐id选择器）
		cols: [
			[{
				field: 'roleId',
				align:'center',
				title: 'ID',
				sort: true,
			}, {
				field: 'name',
				align:'center',
				title: '角色名称',
				align: 'center',
			}, {
				field: 'title',
				align:'center',
				title: '角色标题',
				align: 'center',
			}, {
				field: 'description',
				align:'center',
				title: '角色描述',
				align: 'center',
			}, {
				field: 'orders',
				align:'center',
				title: '排序',
				sort: true,
				align: 'center',
			}, {
				align:'center',
				title: '操作',
				toolbar: '#roleBar'
			}]
		], //设置表头
		url:'/systemsetup/permissionsmanage/role/findPagingQuery',
		page: true,
		loading: true,
		limits: [10,30,60,90,150,300],
		limit: 10 //默认采用60
    });
	
	$('#addRole').on('click', function() {
		 layer.open({
		      type: 2,
		      shadeClose: true,
		      title: '添加权限',
		      maxmin: true, //开启最大化最小化按钮
		      area: ['720px', '370px'],
		      content: '/systemsetup/permissionsmanage/role/addIndex',
		      end: function () {
		    	  	tableIns.reload();
	          },
		 });
	 });
	
	//监听工具条
    table.on('tool(roleList)', function(obj){
	    	var data = obj.data;
	    	console.log(data);
	    	if(obj.event === 'detail'){
	    		layer.open({
	    			  type: 2,
	    			  title:"查看角色",
	    			  area: ['600px', '380px'], //宽高
	    			  content: "/systemsetup/permissionsmanage/role/detailIndex?id="+data.roleId,
	    			  end: function(){
	    				tableIns.reload();
	    			  }
	      	});
	    	} else if(obj.event === 'del'){
	    		layer.confirm('确定要删除吗', {
	    			btn: ['确定','取消'] //按钮
	    		}, function(){
	    			$.post("/systemsetup/permissionsmanage/role/delectRole",{id:data.roleId},function(result){
	    				if (result.status == 200) {
	    					layer.msg(result.msg, {
	    					    	time: 2000, 
	    					});
					} else {
						layer.msg(result.msg, {
					    		time: 2000, 
						});	
					}
	    				tableIns.reload();
	    			});
	    		}, function(){
	    			tableIns.reload();
	    		});
	    	} else if(obj.event === 'edit'){
	    		layer.open({
	    			  type: 2,
	    			  title:"编辑角色",
	    			  area: ['600px', '380px'], //宽高
	    			  content: "/systemsetup/permissionsmanage/role/editIndex?id="+data.roleId,
	    			  end: function(){
	    				tableIns.reload();
	    			  }
	      	});
	    	}
    });
	
	
});